package com.lexy;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.lexy.util.CommMethod;
import com.lexy.util.HttpPostUtils;

public class MainMethod {
	
	
	public static void main(String[] args) throws Exception {
		
		
		String http ="http://";
		String eName = http+"www.aimeishishang.com";
		
		
		String startPage=eName+"/ArisaraKarbdecho/mm4065/";
		
		// 获取页面 document
		Document document = CommMethod.getDocument(startPage);
		 
		
		 
		Elements elementsByTag = document.getElementsByTag("ignore_js_op");
		
		System.out.println(elementsByTag.size());
		List<String> imglist = new ArrayList<String>();
		for (Element element : elementsByTag) {
			Elements elementsByTag2 = element.getElementsByTag("img");
			for (Element obj : elementsByTag2) {
				String attr = obj.attr("src");
				imglist.add(attr);
				System.out.println(attr);
				break;
			}
		}
		String root = "D:\\Manipula\\LexyGet";
		
		if(imglist!=null && imglist.size()>0){
			for (int i = 0; i < imglist.size(); i++) {
				
				String string = imglist.get(i);
				
				String[] split = string.split("/");
				String fileName = split[split.length-1];
				System.out.println(fileName);
				
				
				
				byte[] dealPost = HttpPostUtils.getImgByte(eName+"/"+string);

				System.out.println(dealPost.length);
				File inFile = new File(root+File.separator+fileName);
				FileOutputStream fos = new FileOutputStream(inFile);
				
				fos.write(dealPost);
				fos.close();
				
				
			}
		}
		
	}

	

}
